package utils

func Min(a ...int) int {
	return Pick(Min2, a...)
}

func Max(a ...int) int {
	return Pick(Max2, a...)
}

func Pick(p func(a, b int) int, as ...int) int {
	switch len(as) {
	case 0:
		return -1
	case 1:
		return as[0]
	case 2:
		return p(as[0], as[1])
	default:
		pick := as[0]
		for i := 1; i < len(as); i++ {
			pick = p(pick, as[i])
		}
		return pick
	}
}

func Min2(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func Max2(a, b int) int {
	if a < b {
		return a
	}
	return b
}
